package com.apps.ftapp.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.apps.ftapp.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lyli on 2017/10/6.
 */

public class SubjectAddLeftAdapter extends BaseAdapter {


    List<String> data;
    LayoutInflater inflater;
    private int selectItem = 0;

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
        notifyDataSetChanged();
    }

    public SubjectAddLeftAdapter(Context context) {
        data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            data.add("电影" + i);
        }
        inflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public String getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_subject_add_left_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mText.setText(data.get(position));

        if (selectItem == position) {
            holder.mText.setTextColor(Color.parseColor("#01c475"));
            // holder.mIndicator.setVisibility(View.VISIBLE);
            holder.leftContainer.setBackgroundColor(Color.parseColor("#ffffff"));
        } else {
            holder.mText.setTextColor(Color.parseColor("#999999"));
            //    holder.mIndicator.setVisibility(View.INVISIBLE);
            holder.leftContainer.setBackgroundColor(Color.parseColor("#eaebec"));
        }

        return convertView;
    }

    public static class ViewHolder {

        TextView mText;
        //  View mIndicator;
        LinearLayout leftContainer;

        public ViewHolder(View itemView) {
            mText = itemView.findViewById(R.id.left_text);
            //    mIndicator=itemView.findViewById(R.id.left_indicator);
            leftContainer = itemView.findViewById(R.id.left_container);
        }
    }
}
